package com.pti.fsc.api.restful.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pti.fsc.api.restful.delegate.${entityName}Delegate;
import com.pti.fsc.api.restful.formbean.${entityName}GridForm;
import com.pti.fsc.api.service.${entityName?lower_case}.vo.${entityName}SearchCriteria;
import com.pti.waf.mvc.controller.WafController;
import com.pti.waf.mvc.controller.WafControllerConfig;
import com.pti.waf.mvc.controller.WafModel;
import com.pti.waf.mvc.controller.WafViewer;

public class ${entityName}GridController extends WafController{

	private final static String ACTION_LIST = "/${entityName?uncap_first}List";
	private final static String ACTION_SEARCH = "/${entityName?uncap_first}Search";

	@Override
	public WafViewer wafExecute(WafControllerConfig mapping, WafModel form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		String forwardName = null;
		String action = mapping.getPath();
		${entityName}GridForm ${entityName?uncap_first}GridForm = (${entityName}GridForm)form;
		if(ACTION_LIST.equals(action)){
			${entityName}Delegate delegate = ${entityName}Delegate.getInstance();
			${entityName}SearchCriteria searchCriteria = ${entityName?uncap_first}GridForm.getSearchCriteria();
			${entityName}SearchCriteria _searchCriteria = delegate.search${entityName}(searchCriteria);
			${entityName?uncap_first}GridForm.setSearchCriteria(_searchCriteria);
			${entityName?uncap_first}GridForm.set${entityName}s(_searchCriteria.get${entityName}s());
			forwardName = "${entityName?uncap_first}List";
		}else if(ACTION_SEARCH.equals(action)){
			forwardName = "${entityName?uncap_first}Search";
		}
		return mapping.findViewer(forwardName);
	}
	
}
